﻿using System;
using System.Data;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

using ent;

public partial class sandbox_javascript : System.Web.UI.Page {
    public String URL = ApplicationCommon.getPageThis();

    private int _qsId = 0;

    protected override void OnLoad(EventArgs e) {
        base.OnLoad(e);
        this.Page.Header.DataBind();
    }
    protected void Page_Load(Object sender, EventArgs e) {
        System.Diagnostics.Debug.Write("Page Loaded");
    }

#region Methods

    /// <summary>Output data to page.</summary>
    protected void outputData() {
        // Set the page's content type.	
        Page.Response.ContentType = "text/html";
        // Clear all response headers.
        Page.Response.Clear();
        // Buffer response so that page is sent after processing is complete.
        Response.BufferOutput = true;
        // Write data to the page.
        Page.Response.Write(getData());
        // Send the output to the client.
        Page.Response.Flush();
        // Check whether the browser remains connected to the server.
        if(!Page.Response.IsClientConnected) {
            // If connected, then do something here.
        } else {
            // If the browser is not connected stop all response processing.
            Page.Response.End();
        }        
    }
    /// <summary>Get data from database for Page.Response.Write.</summary>
    protected String getData() {
        if(_qsId == 0) {
            System.Random rand = new System.Random();
            _qsId = rand.Next(200, 999);
        }

        String s = String.Empty;
        s +=
        "<html><head><script type=\"text/javascript\">" +
        "//<![CDATA[" + "\n" +
        "var result = " +
        "{" +
            String.Format("\"{0}\":{1}, ", "intItemId", _qsId) +
            String.Format("\"{0}\":{1}, ", "boolItemPublic", false) +
            String.Format("\"{0}\":\"{1}\", ", "name", "William Chang") +
            String.Format("\"{0}\":\"{1}\"", "description", "Some meta data.") +
        "};" +
        "\n" + "//]]>" +
        "</script></head><body>&nbsp;</body></html>";

        return s;
    }

#endregion

    protected void btnSubmit_Click(Object sender, EventArgs e) {
        System.Diagnostics.Debug.Write("Button Clicked");
        outputData();
    }

}